﻿using System.Collections.Generic;
using System.Configuration;
using System.Web.Mvc;
using WebStickyNotes.Data.Access;
using WebStickyNotes.Helpers;

namespace WebStickyNotes.Controllers
{
    public class ReportsController : Controller
    {
        private readonly string _connectionType;
        private readonly string _connectionString;

        private static readonly List<int> AllowedTaskRoleId = new List<int> { 1 };

        public ReportsController()
        {
            _connectionType = ConfigurationManager.AppSettings["ConnectionType"];
            _connectionString = ConfigurationManager.ConnectionStrings["WebStickyNotesData"].ConnectionString;
        }

        [HttpGet]
        [MustSignIn]
        public ActionResult Index()
        {
            using (var supplier = new Supplier(_connectionType, _connectionString))
            {
                var currentUser = supplier.DataAccess.GetTaskPerson(SecurityHelper.GetSignedInUserId());
                if (!AllowedTaskRoleId.Contains(currentUser.TaskRoleId))
                {
                    return RedirectToAction("AccessDenied", "Home", new { address = HttpContext.Request.Url.AbsoluteUri });
                }

                return View();
            }
        }

    }
}
